﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GMS.BIZ;
using System.Data;

namespace Web.News
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!((Account)Session["Account"]).RoleCurrent.Equals('a')) Response.Redirect("Default.aspx");
            if (((Admin)Session["Admin"]).TeacherName == "")
                Response.Redirect("~/Information/TeaInformation.aspx");
            refreshgrvnews();
        }

        protected void refreshgrvnews()
        {
            GMS.BIZ.News myNews = new GMS.BIZ.News();
            DataSet ds = myNews.GetList("1=1 ORDER BY news_date desc");
            if (ds.Tables[0].Rows.Count == 0)
            {
                Label_noData.Text = "没有公告信息，请点击修改进行添加";
            }
            else
            {
                GridView_News.DataSource = ds;
                GridView_News.DataBind();
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton newImageButton = (ImageButton)sender;
            Response.Redirect("GongGaoDetail.aspx?id=" + newImageButton.CommandArgument);
        }

        protected void ImageButton_Edit_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("AdminGongGaoEdit.aspx");
        }

        protected void GridView_News_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView_News.PageIndex = e.NewPageIndex;
            refreshgrvnews();
        }
    }
}
